//
//  ChangeAddressVC.m
//  hnGovernment
//
//  Created by 安仔 on 17/3/6.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "ChangeAddressVC.h"
#import "XJTextView.h"

@interface ChangeAddressVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) XJTextView *addressTextView;
@property (nonatomic, strong) UISwitch *mySwitch;

@end

@implementation ChangeAddressVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalString(@"修改地址");
    self.view.backgroundColor = BackgroundColor;
    
    
    UIBarButtonItem *rightbuttonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(rightFun)];
    [rightbuttonItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = rightbuttonItem;
    
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight - 128 * m6Scale) style:UITableViewStyleGrouped];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];

    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 6;
    }
    else {
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 && indexPath.row == 5) {
        return 240 * m6Scale;
    }
    else {
        return 100 * m6Scale;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 20 * m6Scale;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
 
    return 0.01;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell * cell = [self.myTableView dequeueReusableCellWithIdentifier:@"changeAddressCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"changeAddressCell"];
        cell.textLabel.textColor = RGB(103, 103, 103);

        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                cell.textLabel.text = NSLocalString(@"联系人");
            }
            else if (indexPath.row == 1) {
                cell.textLabel.text = NSLocalString(@"电话");

            }
            else if (indexPath.row == 2) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.text = NSLocalString(@"省、市、县");

            }
            else if (indexPath.row == 3) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.text = NSLocalString(@"街道");

            }
            else if (indexPath.row == 4) {
                cell.textLabel.text = NSLocalString(@"邮编");

            }
            else {
                
                self.addressTextView = [[XJTextView alloc] init];
                self.addressTextView.placeholder = NSLocalString(@"请填写详细地址，不少于5个字");
                [self.addressTextView setValue:[UIFont systemFontOfSize:32 * m6Scale] forKeyPath:@"_placeholderLabel.font"];
                self.addressTextView.font = [UIFont systemFontOfSize:32 * m6Scale];
                [cell addSubview:self.addressTextView];
                [self.addressTextView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(cell.mas_left).offset(5 * m6Scale);
                    make.top.mas_equalTo(cell.mas_top).offset(10 * m6Scale);
                    make.size.mas_equalTo(CGSizeMake(cell.frame.size.width - 10 * m6Scale, 220 * m6Scale));
                }];
            }

        }
        else{
            cell.textLabel.text = NSLocalString(@"设为默认");
            self.mySwitch = [[UISwitch alloc] init];
            [cell addSubview:self.mySwitch];
            [self.mySwitch mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(cell.mas_right).offset(-30 * m6Scale);
                make.centerY.mas_equalTo(cell.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(104 * m6Scale, 62 * m6Scale));
            }];
                    
        }
    }

    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
